package com.yuanchu.goods.utils;

import com.yuanchu.goods.entity.YoshopUploadFileEntity;
import lombok.Data;

import static com.yuanchu.common.utils.DateFormatUtils.formatDatetime;

/**
 * @version: 1.0
 * @Author: adan
 * @description: 文件格式化工具类
 * @date: 2023-12-23 16:45
 */
@Data
public class FormatUtils {


    public static YoshopUploadFileEntity formatFile(YoshopUploadFileEntity file) {
        Integer fileType = file.getFileType();
        if (fileType == 30){
            file.setPreviewUrl("https://mytake.oss-cn-guangzhou.aliyuncs.com/video-file.png");
        } else if (fileType == 20) {
            file.setPreviewUrl("https://mytake.oss-cn-guangzhou.aliyuncs.com/annex-flie.png");
        }else {
            // file.setPreviewUrl("http://8.134.205.222:8001/uploads/" + file.getFilePath());
            file.setPreviewUrl(file.getDomain() + file.getFilePath());
        }
        // file.setExternalUrl("http://8.134.205.222:8001/uploads/" + file.getFilePath());
        file.setExternalUrl(file.getDomain() + file.getFilePath());
        file.setCreateTime(formatDatetime(file.getCreateTime()));
        file.setUpdateTime(formatDatetime(file.getUpdateTime()));
        return file;
    }

    // 拼接商品预览地址 preview_url和external_url
    // "preview_url": "http:\/\/8.134.205.222:8001\/uploads\/10001\/20231218\/7569c8ad9382d364027b8afc094b7da3.jpg",
    // "external_url": "http:\/\/8.134.205.222:8001\/uploads\/10001\/20231218\/7569c8ad9382d364027b8afc094b7da3.jpg"
/*    public static YoshopUploadFileEntity formatFile(YoshopUploadFileEntity file) {
        Integer fileType = file.getFileType();
        if (fileType == 30){
            file.setPreviewUrl("https://mytake.oss-cn-guangzhou.aliyuncs.com/video-file.png");
        } else if (fileType == 20) {
            file.setPreviewUrl("https://mytake.oss-cn-guangzhou.aliyuncs.com/annex-flie.png");
        }else {
            file.setPreviewUrl("http://8.134.205.222:8001/uploads/" + file.getFilePath());
        }
        file.setExternalUrl("http://8.134.205.222:8001/uploads/" + file.getFilePath());
        file.setCreateTime(formatDatetime(file.getCreateTime()));
        file.setUpdateTime(formatDatetime(file.getUpdateTime()));
        return file;
    }*/


}
